package com.yoofn.kotlin.av.view.fragment

import com.yanzhenjie.nohttp.RequestMethod
import com.yanzhenjie.nohttp.rest.JsonObjectRequest
import com.yanzhenjie.nohttp.rest.Response
import com.yanzhenjie.nohttp.rest.StringRequest
import com.yoofn.kotlin.R
import com.yoofn.kotlin.base.BaseFragment
import com.yoofn.kotlin.base.NetData
import com.yoofn.kotlin.base.ViewConfig
import com.yoofn.kotlin.databinding.FragmentHomeBinding
import org.json.JSONObject

/**
 *
 * Created by kalshen on 17/6/2.
 * @描述 主页fragment
 */
class HomeFragment : BaseFragment<FragmentHomeBinding, String>() {



    override fun setupConfig(): ViewConfig<String> {
        val request = StringRequest("http://192.168.1.111:8087/auth/login", RequestMethod.POST).apply {
            //            addHeader("Content-Type","application/json")
        }
        val s = "{username:\"2\",password:\"2\"}"

        request.setDefineRequestBodyForJson(s)
        return ViewConfig(R.layout.fragment_home, true, true, NetData(0, request))
    }

    override fun doInteractive() {
        with(contentView) {
            btnHomeAddRequest.setOnClickListener { addRequest(NetData<JSONObject>(1, JsonObjectRequest("http://xtk.azurewebsites.net/BingDictService.aspx?Word=c", RequestMethod.GET))) }
            btnHomeShowWeb.setOnClickListener { startWebActivity("http://www.yoofn.com") }

        }
    }


    override fun <ResponseType> doBusiness(what: Int, response: Response<ResponseType>) {
        when (what) {

        }
    }
}
